package com.lego.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.lego.service.AdminService;
import com.lego.service.impl.AdminServiceImpl;

@WebServlet("/adminLogin.do")
public class AdminLoginServlet extends HttpServlet {
	private AdminService as=new AdminServiceImpl();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String adName=req.getParameter("adminName");
		String adPwd=req.getParameter("adminPwd");
		HttpSession session=req.getSession();
		Map<String, Object> map=as.adminLogin(adName, adPwd);
		if(map.get("admin")!=null) {
			session.setAttribute("admin", map.get("admin"));
			resp.sendRedirect("/lego/admin.jsp");
		}else {
			session.setAttribute("msg",map.get("msg"));
			req.getRequestDispatcher("adminLogin.jsp").forward(req, resp);
		}
	}
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}


}
